<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Messagerecord_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
	}
	/*
	 * 返回通知的数量
	 */
	public function count_records(){
		$this->db->where('del=0');
		$query = $this->db->get('t_messagerecord');
		return $query->num_rows();
	}
	/*
	 * 返回通知列表
	 */
	public function get_records($page,$offset){
		$this->db->select('t_messagerecord.id,t_messagerecord.title,t_messagerecord.content,t_messagerecord.time,t_admin.name');
		$this->db->from('t_messagerecord');
		$this->db->join('t_admin', 't_admin.id = t_messagerecord.adminid','left');
		$this->db->limit($page, $offset);
		$this->db->where('del=0');
		$this->db->order_by("id","desc");
		$query=$this->db->get();
		return $query->result_array();
	}
	/*
	 * 根据ID得到通知信息
	 */
	public function load($id){
		$query = $this->db->get_where('t_messagerecord',array('id' => $id));
		if ($row = $query->row_array()){
			return $row;
		}
		return array();
	}
	/*
	 * 保存通知
	 */
	public function create($record){
		$this->db->insert('t_messagerecord', $record);
		return $this->db->insert_id();
	}
	/*
	 * 更新通知信息
	 */
	public function update($id,$record){
		$this->db->where('id', $id);
		$this->db->update('t_messagerecord', $record);
		return $this->db->affected_rows()>0;
	}
}